package site.codeyin.javautils.controller.aspect.spel;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import site.codeyin.javautils.controller.req.SpelReq;
import site.codeyin.javautils.utils.SpElUtils;

/**
 * @author <a href="https://github.com/liangcheng2221">yinjie</a>
 * @date 2024-11-16 23:55
 */
@Aspect
@Component
@Slf4j
public class SpelAspect {
    @Around("@annotation(spel)")
    public Object around(ProceedingJoinPoint joinPoint, Spel spel) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        SpelReq spelReq = SpElUtils.parseSpEl(signature.getMethod(), joinPoint.getArgs(), spel.value(), SpelReq.class);
        log.info("解析的Spel表达式的对象，spelReq:{}", spelReq);
        return joinPoint.proceed();
    }
}
